/* ***********************************************************
   Amplio columna visibilidad de PADR 
 ************************************************************* */

-------------------
-- dropear vista
DROP VIEW public.vpadr;

-------------------
-- cambiar longitud 
-------------------
ALTER TABLE padr
      ALTER COLUMN visibilidad TYPE character varying(54);

-------------------      
-- recrear vista 
-------------------
CREATE OR REPLACE VIEW public.vpadr AS 
 SELECT padr.tipopada,
    padr.cod,
    padr.nombre,
    padr.preitem,
    padr.digitem,
    padr.cp,
    padr.visibilidad,
    padr.bt,
    padr.clasesval,
    padr.accesovenzon,
    padr.signoctacte,
    padr.codvalmon,
    padr.modosrescta,
    padr.modoresctasug,
    padr.aceptaitem,
    padr.tienectacte,
    padr.prefijoambdb,
    padr.controlacuit,
    padr.tipoprepaga,
    padr.defcamposesp,
    padr.accesosucursales,
    padr.accesousuarios,
    padr.codpadiva,
    padr.codctbcosr1,
    padr.codctbcosr2,
    padr.codctbcosr3,
    padr.codctbcosr4
   FROM padr
UNION
 SELECT 'V-'::text || venzoncfg.nrocfg AS tipopada,
    venzon.cod,
    venzon.nombre,
    ''::character varying AS preitem,
    tipos.entero AS digitem,
    ''::character varying AS cp,
    '-'::character varying AS visibilidad,
    ''::character varying AS bt,
    'CV='::character varying AS clasesval,
    'VZ='::character varying AS accesovenzon,
    tipos.entero AS signoctacte,
    '$'::character varying AS codvalmon,
    ''::character varying AS modosrescta,
    ''::character varying AS modoresctasug,
    'S'::character varying AS aceptaitem,
    'N'::character varying AS tienectacte,
    'N'::character varying AS prefijoambdb,
    'N'::character varying AS controlacuit,
    NULL::character varying AS tipoprepaga,
    NULL::character varying AS defcamposesp,
    venzon.accesosucursales,
    venzon.accesousuarios,
    NULL::character varying AS codpadiva,
    NULL::character varying AS codctbcosr1,
    NULL::character varying AS codctbcosr2,
    NULL::character varying AS codctbcosr3,
    NULL::character varying AS codctbcosr4
   FROM venzon
     JOIN tipos ON true
     JOIN venzoncfg ON venzon.nrocfg = venzoncfg.nrocfg
  WHERE venzoncfg.habilitado::text = 'S'::text AND venzoncfg.asociapad::text = 'S'::text;

ALTER TABLE public.vpadr  OWNER TO abacouser;

GRANT ALL ON TABLE public.vpadr TO abacouser;
      

-- =====================================
SELECT aaversion('394.02');
-- =====================================